﻿<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../../resources/js-test.js"></script>
</head>
<body>
<script>
shouldBeEqualToString('window.atob("YQ==")', 'a');
shouldBeEqualToString('window.atob("YWI=")', 'ab');
shouldBeEqualToString('window.atob("YWJj")', 'abc');
shouldBeEqualToString('window.atob("YWJjZA==")', 'abcd');
shouldBeEqualToString('window.atob("YWJjZGU=")', 'abcde');
shouldBeEqualToString('window.atob("YWJjZGVm")', 'abcdef');

shouldBeEqualToString('window.btoa("a")', 'YQ==');
shouldBeEqualToString('window.btoa("ab")', 'YWI=');
shouldBeEqualToString('window.btoa("abc")', 'YWJj');
shouldBeEqualToString('window.btoa("abcd")', 'YWJjZA==');
shouldBeEqualToString('window.btoa("abcde")', 'YWJjZGU=');
shouldBeEqualToString('window.btoa("abcdef")', 'YWJjZGVm');

shouldBeEqualToString('typeof window.btoa', 'function');
shouldThrow('window.btoa()', '"TypeError: Failed to execute \'btoa\' on \'Window\': 1 argument required, but only 0 present."');
shouldBeEqualToString('window.btoa("")', '');
shouldBeEqualToString('window.btoa(null)', 'bnVsbA=='); // Gets converted to "null" string.
shouldBeEqualToString('window.btoa(undefined)', 'dW5kZWZpbmVk');
shouldBeEqualToString('window.btoa(window)', 'W29iamVjdCBXaW5kb3dd'); // "[object Window]"
shouldBeEqualToString('window.btoa("éé")', '6ek=');
shouldBeEqualToString('window.btoa("\\u0080\\u0081")', 'gIE=');
shouldThrow('window.btoa("тест")');
window.btoa = 0;
shouldBe('window.btoa', '0');
shouldBeEqualToString('typeof window.btoa', 'number');

shouldBeEqualToString('typeof window.atob', 'function');
shouldThrow('window.atob()', '"TypeError: Failed to execute \'atob\' on \'Window\': 1 argument required, but only 0 present."');
shouldBeEqualToString('window.atob("")', '');
shouldBeEqualToString('window.atob(null)', '\x9Eée'); // Gets converted to "null" string.
shouldThrow('window.atob(undefined)');

// HTML space characters in input.
shouldBeEqualToString('window.atob(" YQ==")', 'a');
shouldBeEqualToString('window.atob("YQ== ")', 'a');
shouldBeEqualToString('window.atob("YQ==    ")', 'a');
shouldBeEqualToString('window.atob("YQ==\\u000a")', 'a');
shouldBeEqualToString('window.atob("YQ ==")', 'a');
shouldBeEqualToString('window.atob("YQ\\t==")', 'a');
shouldBeEqualToString('window.atob("YQ\\n==")', 'a');
shouldBeEqualToString('window.atob("YQ\\f==")', 'a');
shouldBeEqualToString('window.atob("YQ\\r==")', 'a');
shouldBeEqualToString('window.atob("YQ\\t\\n\\f\\r ==")', 'a');

shouldBeEqualToString('window.atob("6ek=")', 'éé');
shouldBeEqualToString('window.atob("6ek")', 'éé');
shouldBeEqualToString('window.atob("gIE=")', '\u0080\u0081');
shouldThrow('window.atob("тест")');
shouldThrow('window.atob("z")');
shouldBeEqualToString('window.atob("zz")', 'Ï');
shouldBeEqualToString('window.atob("zzz")', 'Ï\u003C');
shouldBeEqualToString('window.atob("zzz=")', 'Ï\u003C');
shouldThrow('window.atob("zzz==")'); // excess pad characters.
shouldThrow('window.atob("zzz===")'); // excess pad characters.
shouldThrow('window.atob("zzz====")'); // excess pad characters.
shouldThrow('window.atob("zzz=====")'); // excess pad characters.
shouldBeEqualToString('window.atob("zzzz")', 'Ï\u003Có');
shouldBeEqualToString('atob("            ")', ''); // whitespace only.
shouldThrow('window.atob("zzzzz")');
shouldThrow('window.atob("z=zz")');
shouldThrow('window.atob("=")');
shouldThrow('window.atob("==")');
shouldThrow('window.atob("===")');
shouldThrow('window.atob("====")');
shouldThrow('window.atob("=====")');
window.atob = 0;
shouldBe('window.atob', '0');
shouldBeEqualToString('typeof window.atob', 'number');

</script>
</body>
</html>
